package com.myhexin.demo.ruleengine;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;

public class QLExpressJavaSyntaxExample {
    public static void main(String[] args) {
        try {
            ExpressRunner runner = new ExpressRunner();
            DefaultContext<String, Object> context = new DefaultContext<>();

            // 创建一个用户对象
            User user = new User("John", 25);
            System.out.println("user:" + user);
            context.put("user", user);

            // 使用 Java 语法访问对象属性和调用方法
            QLExpressUtil.executeAndPrint(runner, context, "user.getName()", "Accessing Object Property");
            QLExpressUtil.executeAndPrint(runner, context, "user.getAge() + 5", "Performing Arithmetic with Object Property");

            // 使用 Java 语法进行对象操作
            QLExpressUtil.executeAndPrint(runner, context, "user.age = 30", "Modifying Object Property");
//            executeAndPrint(runner, context, "user.setAge(30)", "Modifying Object Property");
            System.out.println("user after:" + context.get("user"));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
